package com.example.plist.configure;

import com.example.plist.vo.ThirdApiVo;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class ThridApp {
    private String apiHost;
    private String appId;
    private String appSecret;
    private String provider;
    private String apis;
    private Map<String, ThirdApiVo> apiMaps =new HashMap<>();
    ThridApp next;
    public ThridApp appendProvider(String provider,ThridApp app){


        String [] apis = app.getApis().split(",");
        for(String api :apis){
            String[] methodsApi = api.split(" ");
            ThirdApiVo apiVo = new ThirdApiVo();
            apiVo.setMethods(methodsApi[1]);
            apiVo.setUrl(app.getApiHost()+methodsApi[2]);
            app.apiMaps.put(methodsApi[0],apiVo);
            System.out.println(methodsApi);
        }

        this.next = app;
        this.next.setProvider(provider);
        return this.next;
    }
    public ThridApp findProvider(String provider){
        ThridApp next = this.next;
        while (null != next){

            if(next.getProvider().equals(provider)){
                break;
            }
            next = next.next;

        }
        return next;
    }
    public ThridApp findProvider(String provider,String appId){
        return this;
    }
}
